<!-- 内部法人管理 -->
<template>
    <div>
        <top-bar 
        :searchName.sync="searchName"
        @searchList="searchList"
        @add="viewList('add')"
        @push="push"
        ></top-bar>
        <table-list 
        :tableData='tableData'
        :tableLabels='tableLabels'
        :tableProps='tableProps'
        :tableChangeBtns='tableChangeBtns'
        :hasSera='true'
        >
        </table-list>
    
        <el-pagination
            layout="total, sizes, prev, pager, next, jumper"
            style="margin-top:30px"
            :current-page.sync="pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="totalSize">
        </el-pagination>
    
    </div>
</template>
<script>
import api from '@/api/apiPath'
import tableList from '../common/tableList'
import topBar from '../common/topChangeBar'
export default {
    title:'内部法人管理',
	components: {
        'table-list':tableList,
        'top-bar':topBar
        },
	data () {
		return {
            tableProps:['companyName','companyRepresentative','companyTaxpayer','add'     ,'companyPostalcode','companyPhone' ,'updateTime','updateName','changeBtn'],
            tableLabels:['公司名称'    ,'法定代表人'            ,'纳税人识别号'     ,'公司地址'  ,'邮政编码'          ,'联系电话'      ,'更新时间'    ,'更新人'     ,'操作'],
            tableChangeBtns:[
                {label:"编辑",type:'edit',fn:this.viewList},
                {label:"详情",type:'view',fn:this.viewList},
                {label:"删除",type:'dele',fn:this.deleteItem}
                ],
            tableData:[],
            searchName:"",
            pageNum: 1,
            pageSize: 10,//每页几条
            totalSize: 0,
        }
    },
    methods:{
        handleClick(){},
        //新增查看编辑
        viewList(type,idx){
            let insideId;
            if(type != 'add')  insideId= this.tableData[idx].id;
            this.$router.push({path: '/changeLegalPerson', query: {pageType:type,insideId:insideId}})
            
            },
        //删除
        deleteItem(type,idx){
            this.$confirm(`确定要删除当前列表吗？`, '', {
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(() => {
                
                let params={
                    contractUndersignType:'0',
                    id:this.tableData[idx].id,
                }
                this.axios.post(api.TYPEMPLATEDELETE, params).then(res => {
                    if (res.data.code == 200) {
                        this.tableData.splice(idx,1);
                        this.$message({
                        type: 'success',
                        message: '已删除',
                        });
                    }
                })
                
            }).catch(() => {
                
            });
        },
        searchList(pageNum){
            let param = {
                pageNum:pageNum||this.pageNum,
                pageSize:this.pageSize,
                companyName:this.searchName,
            };
            this.axios.post(api.INITCOMPANYALLLIST, param).then(res => {
                if (res.data.code == 200) {
                    let list = res.data.data.list || [];
                    list.forEach(function (item,index,arr) {
                        let {companyProvince='',companyCity='',companyCounty='',companyAddress=''} = item;
                        companyProvince =  companyProvince?companyProvince:'';
                        companyCity= companyCity?companyCity:'';
                        companyCounty= companyCounty?companyCounty:'';
                        companyAddress= companyAddress?companyAddress:'';
                        let add = companyProvince+companyCity+companyCounty+companyAddress;
                        item.add = add;
                    });
                    this.tableData = list;
                    this.totalSize = res.data.data.total;
                }
            })
            
        },
        push(){
            //调用当前tabled的push
            this.$router.push({path: '/importLegalPerson'})
        },
        handleCurrentChange () {
            this.searchList()
		},
		handleSizeChange (val) {
			this.pageSize = val
			this.searchList(1)
		},
	},
	created () {
        this.searchList();
    },
    activated(){
        this.searchList(1)
    },
	destroyed() {
		
	},
	filters: {

	}
}

</script>

<style lang="stylus" scoped>


</style>
